<template>
  <div class="form-wrap">
    <div class="clearfix title">
      <span class="h3">小程序角色管理</span>
      {{ title }}
    </div>
    <keep-alive>
      <router-view
        :exportable="true"
        :creatable="false"
        :table-title="tableTitle"
        :table-data="tableData"
        :create-path="createPath"
        :get-table-list="getTableList"
        :show-pagination="true"
        :default-operate="false"
        :deletable="false"
        @childTitle="childTitle"
        @edit="edit"
        @selectionChange="selectionChange"
        @del="del"
      />
    </keep-alive>
  </div>

</template>

<script>

  export default {
    data() {
      return {
        title: '',
        defaultOperate: false,
        createPath: 'miniprogram.user.create',
        tableTitle: [
          {
            cn: 'id',
            en: 'fansid'
          },
          {
            cn: '名称',
            en: 'fansname'
          },
          {
            cn: '所属公司',
            en: 'conpaniesname'
          },
          {
            cn: '创建时间',
            en: 'created_at'
          },
          {
            cn: '更新时间',
            en: 'updated_at'
          }
        ],
        tableData: []
      }
    },
    methods: {
      getTableList(data, pageInfo) {
        const loading = this.$loading()
        this.$get('action/WxUserCtrl/dataGrid', data).then(res => {
          const list = res.data.list
          pageInfo.totalPage = res.data.totalPage
          pageInfo.totalRow = res.data.totalRow

          this.tableData = list
          loading.close()
        })
          .catch(_ => {
            loading.close()
          })
      },

      selectionChange(val) {
        // console.log(val);
      },

      del(val) {
        if (val) {
          // 点单个删除
          this.tableData.splice(val.$index, 1)
          this.$post('action/AdminMenu/del', {id: val.row.id})
            .then(res => {

            })
        } else {
          // 点批量删除

        }
      },
      childTitle(val) {
        this.title = val
      },

      edit(val) {
        let details = val.row
        if  (details.mps_id==='null'){
          details.mps_id = []
        }
        this.$router.push({
          name: 'miniprogram.user.edit',
          query: {
            details: JSON.stringify(details)
          }
        })
      }
    }
  }
</script>

<style scoped rel="stylesheet/scss" lang="scss">
  .form-wrap {
    padding: 0 15px;

    .title {
      padding: 15px 0;
    }
  }
</style>
